package com.yanxml.springboot.core.listener.custom.business_event.controller;

import com.yanxml.springboot.core.listener.custom.business_event.event.MyCustomApplicationEvent;
import com.yanxml.springboot.core.listener.custom.business_event.publisher.MyEventPublisher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(path = "/hello_event")
public class HelloEventController {

    @Autowired
    private MyEventPublisher eventPublisher;

    @RequestMapping(path = "/invoke_hello_event", method = RequestMethod.GET)
    @ResponseBody
    public String invokeHelloEvent() {
        eventPublisher.publishCustomEvent(new MyCustomApplicationEvent(null, "invoke_hello"));
        return "hello";
    }
}
